package a06;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import javax.annotation.PostConstruct;

/**
 * Aware接口用来注入一些信息：
 * BeanNameAware：注入Bean的名字
 * ApplicationContextAware：注入容器
 * BeanFactoryAware：注入BeanFactory
 * 等等
 * 像注解@Autowire，就能实现注入的功能，为什么还需要这些Aware呢？
 * 像@Autowire是有扩展的后处理器来解析的，可能会失效。但是Aware是Spring内置的功能，不会失效
 *
 */
public class MyBean implements BeanNameAware, ApplicationContextAware, InitializingBean {
    @Override
    public void setBeanName(String name) {
        System.out.println("name>>>>" + name);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("applicationContext>>>>>>>>>" + applicationContext);
    }


    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("初始化...........");
    }

    @PostConstruct
    public void init() {
        System.out.println(">>>>>>>PostConstruct");
    }
}
